package com.example.springbootdemo;

public class MainThreadExample {

    // 自定义线程类，继承Thread
    static class ChildThread extends Thread {
        @Override
        public void run() {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                    System.out.println("子线程执行: " + i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("子线程结束");
        }
    }

    public static void main(String[] args) {
        // 创建并启动子线程
        ChildThread childThread = new ChildThread();
        childThread.start();

        System.out.println("主线程结束");
        // 主线程结束后，子线程会继续执行
    }
}